package service.impl;

import java.util.Date;
import java.util.Map;

import model.EstpInfo;
import model.ProjectInfo;
import model.User;
import service.EstpInfoManager;


import com.opensymphony.xwork2.ActionContext;

import dao.EstpInfoDao;
import java.util.List;
public class EstpInfoManagerImpl implements EstpInfoManager {
	private EstpInfoDao estpInfoDao;
	
	public EstpInfoDao getEstpInfoDao() {
		return estpInfoDao;
	}

	public void setEstpInfoDao(EstpInfoDao estpInfoDao) {
		this.estpInfoDao = estpInfoDao;
	}

	public int addEstpInfoManager(String estpName, int estpSex,
			Date estpBirthday, int education, int degree,
			int stuProject, int professional, int job,
			int continent, String decIdno, String city, String company,
			int comPerson, String estpPhone, String estpCoPhone,
			String inFax, String email) throws Exception {
		try {
			EstpInfo ei = new EstpInfo();
			ei.setEstpName(estpName);
			ei.setEstpSex(estpSex);
			ei.setEstpBirthday(estpBirthday);
			ei.setEducation(education);
			ei.setDegree(degree);
			ei.setStuProject(stuProject);
			ei.setProfessional(professional);
			ei.setJob(job);
			ei.setContinent(continent);
			ei.setDecIdno(decIdno);
			ei.setCity(city);
			ei.setCompany(company);
			ei.setComPerson(comPerson);
			ei.setEstpPhone(estpPhone);
			ei.setEstpCoPhone(estpCoPhone);
			ei.setInFax(inFax);
			ei.setEmail(email);
			Map session = ActionContext.getContext().getSession();
			String eduFile = (String)session.get("EduFile");
			String degreeFile = (String)session.get("DegreeFile");
			User user = (User)session.get("USER");
			ei.setEduFile(eduFile);
			ei.setDegreeFile(degreeFile);
			ei.setUser(user);
			estpInfoDao.save(ei); 
			return ei.getId();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("新增创业者信息时出现异常");
		}
		// TODO Auto-generated method stub
	}
	
	public EstpInfo getEstpById(int id) throws Exception{
		try {
			EstpInfo ei = estpInfoDao.get(id);
			return ei;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("按id查找创业者信息时出现异常");
		}
	}
	public List<EstpInfo> getEstpByUser(User user) throws Exception{
		try {
			List<EstpInfo> eInfo = estpInfoDao.getEstpByUser(user);
			return eInfo;
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("按用户查找创业者信息时出现异常");
		}
	}
	public int addOrUpdateEstpInfoManager(String estpName, int estpSex, Date estpBirthday,int education,
			int degree,int stuProject,int professional,
			int job,int continent,String decIdno,String city,
			String company,int comPerson,String estpPhone,String estpCoPhone,
			String inFax, String email) throws Exception{
		try {
			Map session = ActionContext.getContext().getSession();
			EstpInfo ei = (EstpInfo)session.get("E");
			if(ei == null){
				ei = new EstpInfo();
			}
			ei.setEstpName(estpName);
			ei.setEstpSex(estpSex);
			ei.setEstpBirthday(estpBirthday);
			ei.setEducation(education);
			ei.setDegree(degree);
			ei.setStuProject(stuProject);
			ei.setProfessional(professional);
			ei.setJob(job);
			ei.setContinent(continent);
			ei.setDecIdno(decIdno);
			ei.setCity(city);
			ei.setCompany(company);
			ei.setComPerson(comPerson);
			ei.setEstpPhone(estpPhone);
			ei.setEstpCoPhone(estpCoPhone);
			ei.setInFax(inFax);
			ei.setEmail(email);
			String eduFile = (String)session.get("EduFile");
			String degreeFile = (String)session.get("DegreeFile");
			User user = (User)session.get("USER");
			ei.setEduFile(eduFile);
			ei.setDegreeFile(degreeFile);
			ei.setUser(user);
			estpInfoDao.saveOrUpdate(ei);
			return ei.getId();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("新增或更新创业者信息时出现异常");
		}
		
	}

}
